package io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class IODemo4 {
    public static void main(String[] args) throws IOException {
        try (InputStream input=new FileInputStream("./test.txt")){
            //一个字节一个字节进行读取
            /*while (true){
                int n=input.read();
                //当n=-1就表示文件读取完毕了
                if(n==-1){
                    break;
                }
                System.out.printf("%x ",n);//ascll码值是10进制的但是16进制的就是61开始
            }*/
           while (true){

                //进行一段字节进行读取
                byte[] buffer=new byte[1024];
                int n=input.read(buffer);
                if (n==-1){
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("%x ", buffer[i]);
                }
                String s=new String(buffer,0,n);
                System.out.println(s);
            }
        }
        /*InputStream inputStream=null;
        try {
            inputStream=new FileInputStream("");
        }finally {
            inputStream.close();
        }*/
    }
}
